home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Events.c
-
- Contains: Main event loop and basic keyboard/mouse processing
-
- Written by: Chris White, Developer Technical Support
-
- Copyright: © 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- 03/29/96 CW First release
-
- */
-
-
- #pragma segment Core
-
-
- // System Includes
-
- #ifndef __MEMORY__
- #include <Memory.h>
- #endif
-
- #ifndef __APPLEEVENTS__
- #include <AppleEvents.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __DESK__
- #include <Desk.h>
- #endif
-
- #ifndef __WINDOWS__
- #include <Windows.h>
- #endif
-
-
-
-
- // Application includes
-
- #ifndef __BAREBONES__
- #include "BareBones.h"
- #endif
-
- #ifndef __PROTOTYPES__
- #include "Prototypes.h"
- #endif
-
-
-
-
- // static includes
-
- static void DoMouseDown ( EventRecord* theEvent );
- static void DoKey ( EventRecord*theEvent );
-
-
-
-
-
-
- void EventLoop ( void )
- {
- OSErr theErr;
- EventRecord theEvent;
-
-
- while ( !gQuit )
- {
- WaitNextEvent ( everyEvent, &theEvent, gSleepTime, nil );
-
- switch ( theEvent.what )
- {
- case mouseDown:
- DoMouseDown ( &theEvent );
- break;
-
- case keyDown:
- case autoKey:
- DoKey ( &theEvent );
- break;
-
- case activateEvt:
- DoActivate ( &theEvent );
- break;
-
- case updateEvt:
- DoUpdate ( (WindowRef) theEvent.message );
- break;
-
- case osEvt:
- if ( (theEvent.message >> 24) & suspendResumeMessage ) // suspend or resume
- {
- if ( (theEvent.message >> 24) & resumeFlag )
- SetCursor ( &qd.arrow );
-
- // Modify the event record to look like an activate/deactivate event
- theEvent.modifiers = theEvent.message; // Copy suspend/resume flag
- theEvent.message = (long) FrontWindow ( );
- DoActivate ( &theEvent );
- }
- break;
-
- case kHighLevelEvent:
- theErr = AEProcessAppleEvent ( &theEvent );
- break;
- }
- }
-
- return;
-
- } // EventLoop
-
-
-
- static void DoMouseDown ( EventRecord* theEvent )
- {
- Point globalPt = theEvent->where;
- SInt16 windowPart;
- WindowRef theWindow;
- long theMenu;
-
-
- windowPart = FindWindow ( globalPt, &theWindow );
- switch ( windowPart )
- {
- case inMenuBar:
- theMenu = MenuSelect ( globalPt );
- MenuDispatch ( theMenu );
- break;
-
- case inSysWindow:
- // The SystemClick toolbox routine handles system events
- SystemClick ( theEvent, theWindow );
- break;
-
- case inGoAway:
- // We'll quit when the user closes the window
- if ( TrackGoAway ( theWindow, theEvent->where ) )
- gQuit = true;
- break;
-
- // TO DO: Check order of this switch
- case inGrow:
- DoGrowWindow ( theWindow, theEvent );
- break;
-
- case inDrag:
- DoDragWindow ( theWindow, theEvent );
- break;
-
- case inContent:
- DoContentClick ( theWindow, theEvent );
- break;
- }
-
- return;
-
- } // DoMouseDown
-
-
-
- static void DoKey ( EventRecord* theEvent )
- {
- char keyPressed = (theEvent->message & charCodeMask);
-
-
- // Command keys get handled by the menu handling routines
- if ( theEvent->modifiers & cmdKey )
- MenuDispatch ( MenuKey ( keyPressed ) );
-
- return;
-
- } // DoKey
-
-
-
-
-